from typing import Text
from sqlalchemy import Integer, ForeignKey, String, Text
from sqlalchemy.orm import Mapped, mapped_column, relationship
from model.baseModel import BaseModel

class BlogCategory(BaseModel):
    __tablename__ = "blog_category"

    id: Mapped[int] = mapped_column(primary_key=True)
    title: Mapped[str] = mapped_column(String(10), comment="博客类型标题", nullable=False)

    def __repr__(self) -> str:
        return f"BlogCategory(id={self.id!r}, title={self.title!r})"

class Blog(BaseModel):
    __tablename__ = "blog"

    id: Mapped[int] = mapped_column(Integer, primary_key=True)
    title: Mapped[str] = mapped_column(String(50), comment="博客标题", nullable=False)
    content: Mapped[str] = mapped_column(Text, comment="博客内容", nullable=False)
    category_id: Mapped[int] = mapped_column(ForeignKey("blog_category.id"), comment="博客类型id", nullable=False)
    user_id: Mapped[int] = mapped_column(ForeignKey("user.id"), comment="用户id", nullable=False)

    category: Mapped["BlogCategory"] = relationship(
        "BlogCategory", backref="blog", foreign_keys=[category_id]
    )

    user: Mapped["User"] = relationship(
        "User", backref="blog", foreign_keys=[user_id]
    )

    def __repr__(self) -> str:
        return f"Blog(id={self.id!r}, title={self.title!r})"